package com.example.essayjoke.utils;

import android.content.res.Resources;
import android.util.DisplayMetrics;

/**
 * <p>Title: ScreenSizeUtils</p>
 * <p>Description: 获取屏幕宽高参数辅助工具 </p>
 * <p>Copyright: DaSheng Technology Co.Ltd  Copyright (c) 2020</p>
 * <p>Company: www.ds.cn</p>
 *
 * @author yerundong@ds.cn
 * @version 1.0
 * @date 2020/11/3 17:42
 */

public class ScreenSizeUtils {

    /**
     * 宽度: px
     */
    private static int width = 0;
    /**
     * 高度: px
     */
    private static int height = 0;


    /**
     * 获取屏幕宽高
     */
    private static void getScreenSize() {
        Resources resources = Resources.getSystem();
        DisplayMetrics dm = resources.getDisplayMetrics();
        width = dm.widthPixels;
        height = dm.heightPixels;
    }

    /**
     * 获取屏幕宽度
     * @return      宽度
     */
    public static int getWidth() {
        if (width == 0) {
            getScreenSize();
        }
        return width;
    }

    /**
     * 获取屏幕高度
     * @return      高度
     */
    public static int getHeight() {
        if (height == 0) {
            getScreenSize();
        }
        return height;
    }
}
